package com.sagframe.sagacity.sqltoy.plus;

import java.util.ArrayList;
import java.util.List;

public abstract class ISqlAssemble<T extends FiledMappingStrategy, E extends ISqlAssembler<T>> {

    private boolean isAssemble;

    private List<E> assemblers;

    public ISqlAssemble() {
        this.assemblers = new ArrayList<>();
    }

    public void add(E assembler) {
        assemblers.add(assembler);
    }

    public boolean isEmpty() {
        return assemblers == null || assemblers.isEmpty();
    }

    public void assemble(T mappingStrategy) {
        if (isAssemble) {
            return;
        }
        if (isEmpty()) {
            return;
        }
        for (E sqlAssembler : assemblers) {
            sqlAssembler.assemble(mappingStrategy);
        }
        isAssemble = true;
    }
}
